<?php
use App\Utils;
?>
@extends('layouts.master3')
@section('css')
    <link rel="stylesheet" href="/css/edit/style.css">
    <link rel="stylesheet" href="/css/edit/editormd.css">
    <link rel="stylesheet" href="/css/highlight/styles/github.css">
<style>
			body{padding-bottom:0;}
			#layout{
				width: 1200px;
				margin: 0 auto;
			}
			input.btn{
				margin:20px 60px ;
			}
		</style>

<link href="/css/study_data.css" rel="stylesheet">
@endsection


@section('content')


<!-- Main Content -->


<?php
foreach($comments as $comment)
{
?>
    <div class="data_contain markdown-body" id="{{Utils::id2url($comment->id)}}" style="margin-left:120px;">

        <div class="pull-left data_detail" style="width:900px;margin-left: 10px;" align="left">

            <div class="media">
                <div class="media-body">
                    <div class="media-heading"> <font color="#FF0000">
                            <?php if($comment->type==0) echo "题后评论";
                            else if($comment->type==1) echo "学习资料";
                            else echo "讨论区评论";?>
                            --- 用户:{{$comment->username}} 题目:{{$comment->title}} </font>
                    </div>
                </div>
            </div>
            <br>

            <div class="post-preview">
				<?php echo $comment->content;?>
				<p> 发布于 {{$comment->updated_at}} 
					<?php echo '<a target="_blank" href="/task/setcontenttype?id='.$comment->id.'&zeditor=1'.'">通过</a>';?>
					<?php echo '<a target="_blank" href="/task/setcontenttype?id='.$comment->id.'&zeditor=-1'.'">不通过</a>';?>
					<?php if($comment->type==1) echo '<a target="_blank" href="/task/setcontenttype?id='.$comment->id.'&zeditor=1&jinghua=1'.'">设为精华</a>';?>
				</p>
            </div>
        </div>
    </div>
<?php
}
?>
<br>
<br>
<br>
@stop
@section("js")
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript"
        src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script src="/js/jquery.upvote.js"></script>
<script type="text/javascript">
    $(".hehe").bind("click",function (){
        $(this).parent().parent().next().toggle();
        if($(this).text()!="收起评论")
            $(this).text("收起评论");
        else $(this).text($(this).attr("num")+"条评论");
    });
    $("button.up").click(function(){
        var data_id=$(this).parent().attr("data-id");
        var vote_;
        var this_=$(this);
        $("button.down").removeClass("press").attr("data-statu",false).attr("title","反对，不显示名字");
        $(this).toggleClass("press");
        if($(this).hasClass("press")){
            vote_=1;
            vote(data_id,vote_,this_);
          $(this).attr("title","取消赞同");
          $(this).attr("data-statu",true);
        }
        else{
            vote_=-1;
            vote(data_id,vote_,this_);
            $(this).attr("title","赞同");
            $(this).attr("data-statu",false);
        }
    });
    $("button.down").click(function(){
        $("button.up").removeClass("press").attr("data-statu",false).attr("title","赞同");
        $(this).toggleClass("press");
        if($(this).hasClass("press")){
            $(this).attr("title","取消反对");
            $(this).attr("data-statu",true);
        }
        else{
            $(this).attr("title","反对，不显示名字");
            $(this).attr("data-statu",false);
        }
    });
    function vote(data_id,vote,this_){
        $.get("http://www.qlcoder.com/task/vote",{dataid:data_id,vote:vote,token:0},function(data){
            $(this_).children("span.count").html(data);
        })
    }
    $(".reply").each(function(){
        $(this).click(function(){
            //$(".ql_comment_form").hide();
            $(this).parent().parent().parent().siblings().find(".ql_comment_form").hide();
            $(this).parent().siblings(".ql_comment_form").toggle();
        })
    })
    //    取消评论
    $(".ql_command_cancel").click(function(){
        $(this).parent().parent(".ql_comment_form").toggle();
    })

</script>


<script type='text/javascript'>
    /* attach a submit handler to the form */
    $(".cform").submit(function(event) {
      /* stop form from submitting normally */
      event.preventDefault();

      /* get some values from elements on the page: */
      var $form = $( this ),
          url = $form.attr( 'action');
          var ans=$(this).find("[name='answer']").val();
	ans=ans.replace(/\n/g, "<br>");
          $(this).parent().prev().prev().append(' <div class="media"><a class="pull-left"> <img class="img-circle" alt="Cinque Terre" width="30" height="30" src="{{Auth::user()->avatar->url('thumb')}}" alt=""></a><div class="media-body"><div class="media-heading">{{Auth::user()->name}}<small> 最近发布</small></div>'+ans+'</div></div>');
          $(this).find("[name='answer']").val("");
      /* Send the data using post */
      var posting = $.post( url, { comment: ans,cid:$(this).find("[name='cid']").val(),_token:'{{csrf_token()}}'});

      /* Alerts the results */
      posting.done(function( data ) {
                     // var div=document.getElementById("abc");
      });
    });
</script>

<script src="http://www.qlcoder.com/js/editormd.js?v=1.0"></script>
<script type="text/javascript">
    var testEditor;
    $(function() {
        editormd.methodOne = function() {
        };

        testEditor = editormd("test-editormd", {
            width  : "90%",
            height : 720,
            path   : '/lib/',
            onload : function() {
            }
        });

        editormd.methodOne();
    });
</script>
<script src="http://www.qlcoder.com/js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
@stop
